# coding=utf-8
from zentao.xmind import Xmind
from zentao.excel import Excel


class ZenTao(object):
    
    def __init__(self, import_type, path):
        self.import_type = import_type
        self.path = path
        self.file_suffix = self.judge_file_suffix()
    
    def check_case_type(self):
        """校验用例导入的类型
        :return:
        """
        # XMind导入
        if self.file_suffix == 'xmind':
            return Xmind(self.import_type, self.path).case_type_check()
        # excel导入
        elif self.file_suffix == 'xlsx':
            return Excel(self.import_type, self.path)
    
    def judge_file_suffix(self):
        """判断文件类型
        :param file:文件
        :return:
        """
        # 取最后一个 如：需求v2.1.0.xmind
        file_suffix = self.path.split('.')[-1]
        if file_suffix not in ['xmind', 'xlsx']:
            raise Exception('请选择xmind或者excel文件导入')
        return file_suffix
